<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%
	String path = request.getScheme() + "://" + request.getServerName()
			+ ":" + request.getServerPort() + request.getContextPath()
			+ "/";
	request.setAttribute("path", path);
%>
<base href="<%=path%>"></base>
<title>缺陷等级确认</title>
<link rel="stylesheet" type="text/css"
	href="jquery-easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="jquery-easyui/themes/icon.css">
<script type="text/javascript" src="jquery-easyui/jquery.min.js"></script>
<script type="text/javascript" src="jquery-easyui/jquery.easyui.min.js"></script>
</head>
<body>
	<!-- datagrid 显示数据 -->
	<table id="dg" style="width: 1150px; height: 600px"
		data-options="rownumbers:true,singleSelect:true,pagination:true,method:'get'">
		<thead>
			<tr>
				<th data-options="field:'taskid',width:50">任务编号</th>
				<th data-options="field:'linecode',width:100">路线编号</th>
				<th data-options="field:'polecode',width:100">杆塔编号</th>
				<th data-options="field:'buglevelname',width:100">缺陷类型</th>
				<th data-options="field:'intactrate',width:50">完好率</th>
				<th data-options="field:'bugdesc',width:200">缺陷描述</th>
				<th data-options="field:'discovertime',width:150">发现时间</th>
				<th data-options="field:'discoverercode',width:150">发现人员</th>
				<th
					data-options="field:'buglevel',width:250,align:'center',formatter:op">缺陷级别</th>
			</tr>
		</thead>
	</table>
	<!-- 辅助的小按钮 -->
	<div id="toolbar">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-add" plain="true" onclick="changeBugLever()">Save</a>
		<s:form id="ff">
			<table>
				<tr>
					<td><label>任务编号</label></td>
					<td><s:textfield name="psInspTaskDetail.taskid" /></td>
					<td><label>线路编号</label></td>
					<td><s:textfield name="psInspTaskDetail.linecode" /></td>
					<td><label>杆塔编号</label></td>
					<td colspan="2"><s:textfield name="psInspTaskDetail.polecode" /></td>
					<td align="center"><label>发现人</label></td>
					<td><s:textfield name="psInspTaskDetail.discoverercode" /></td>
				</tr>
				<tr>
					<td><label>缺陷类型</label></td>
					<td><s:textfield class="easyui-combobox" width="100px"
							panelHeight='auto'
							data-options="valueField:'value',textField:'value'"
							name="psInspTaskDetail.buglevelname" id="buglevelnamecc" /></td>
					<td><label>缺陷级别</label></td>
					<td><s:textfield class="easyui-combobox" width="100px"
							panelHeight='auto'
							data-options="valueField:'value',textField:'value'"
							name="psInspTaskDetail.buglevel" id="buglevelcc" /></td>
					<td><label>发现时间</label></td>
					<td colspan="2"><s:textfield class="easyui-datebox"
							name="discoverStartTime" />to<s:textfield class="easyui-datebox"
							name="discoverEndTime" /></td>
					<td align="right"><label><input type="button"
							value="查询" onclick="search()"></label></td>
				</tr>
			</table>
		</s:form>
	</div>
	<script type="text/javascript">
		//formatter缺陷级别
		function op(val, row) {
			var id = row.id;
			return "<input name='psInspTaskDetail.buglevel' id='buglevelchange+"+id+"' class='easyui-combobox buglevel'/>";

		}
		function showMesage(msg) {
			$.messager.show({
				title : '执行结果',
				msg : msg,
				showType : 'show'
			});
		}

		function changeBugLever(obj) {
			var row = $('#dg').datagrid('getSelected');
			var id=row.id;
			var buglevel=$("input[id$='"+id+"'],input[id^='buglevelchange']").combobox('getValue');
			$.ajax({
				url : 'insptaskDetail/changeBugLever',
				data : {
					'psInspTaskDetail.id' : id,
					'psInspTaskDetail.buglevel' : buglevel
				},
				dataType : 'json',
				success : function(data) {
					showMesage(data.message);
					$('#dg').datagrid('reload');
				}
			});
		}
		//查询
		function search() {
			/* $('#ff').form('submit', {
			url : 'insptaskDetail/showInsp',
			onSubmit : function(param) {
				//console.log($('#ff').serialize());
			},
			success : function(data) {
				data = eval('(' + data + ')');
				$('#dg').datagrid('loadData',
						data
				);
			}
			}); */
			var param = $('#ff').serializeJson();
			$('#dg').datagrid({
				queryParams : param
			});

		}
		
		(function($) {
			$.fn.serializeJson = function() {
				var serializeObj = {};
				var array = this.serializeArray();
				var str = this.serialize();
				$(array)
						.each(
								function() {
									if (serializeObj[this.name]) {
										if ($.isArray(serializeObj[this.name])) {
											serializeObj[this.name]
													.push(this.value);
										} else {
											serializeObj[this.name] = [
													serializeObj[this.name],
													this.value ];
										}
									} else {
										serializeObj[this.name] = this.value;
									}
								});
				return serializeObj;
			};
		})(jQuery);

		//初始化
		$(function() {
			$('#dg').datagrid({
				toolbar : '#toolbar',
				url : 'insptaskDetail/showInsp'
			}).datagrid({
										onLoadSuccess: function(){
												$('.buglevel').combobox({
													url : 'config/findDistinctConfigValueId',
													valueField:'value',    
												    textField:'value' 
												}).combobox('setValue', '请选择');			
										}
									}) ;

			$('#buglevelcc').combobox({
				url : 'config/findDistinctConfigValueId'
			});
			$('#buglevelnamecc').combobox({
				url : 'config/findDistinctConfigValueName'
			});

		})
	</script>
</body>
</html>